package com.mvd.app.ac2020;

import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.lzy.okgo.OkGo;
import com.mvd.app.R;
import com.mvd.app.activity.BaseActivity;
import com.mvd.app.adapter.MyProvincesListAdapter2;
import com.mvd.app.application.BaseApplication;
import com.mvd.app.commons.Constants;
import com.mvd.app.commons.SharedPreferencesUtils;
import com.mvd.app.commons.UtilsLog;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author Administrator
 * @version V1.0
 * @Title: DengLuActivity
 * @Package com.mvd.app.ac2020
 * @Description: 新增的车辆登陆功能---不是pda登录界面
 * @date 2020-08-18 17:20
 **/
public class DengLuActivity extends BaseActivity {
    @BindView(R.id.ac_car_denglu_chepai_haoma)
    EditText acCarDengluChepaiHaoma;
    @BindView(R.id.ac_car_denglu_cartype)
    EditText acCarDengluCartype;
    @BindView(R.id.ac_car_denglu_waijianchedao)
    TextView acCarDengluWaijianchedao;
    @BindView(R.id.ac_car_denglu_type)
    EditText acCarDengluType;
    @BindView(R.id.ac_car_denglu_vin)
    EditText acCarDengluVin;
    @BindView(R.id.ac_car_denglu_jiance_ype)
    TextView acCarDengluJianceYpe;
    @BindView(R.id.ac_car_denglu_cancle)
    Button acCarDengluCancle;
    @BindView(R.id.ac_car_denglu_denglu)
    Button acCarDengluDenglu;
    private int CHECK_MODE = 0;
    private String Login_name = "", login_IDNumber;//当前登录的检测员的名字
    public DengLuActivity instances = null;
    private String Line = "1";
    private int index = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_deng_lu);
        ButterKnife.bind(this);
        instances = this;
        setBackBtn();
        setTopTitle("车辆登陆");
        Login_name = getIntent().getExtras().getString("login_UserID", "");
        login_IDNumber = getIntent().getExtras().getString("login_IDNumber", "");
        CHECK_MODE = BaseApplication.JIANCE_MODE;
        UtilsLog.e(instances.getClass().getName()+"==CHECK_MODE==" + CHECK_MODE);
        pop_jiance_type();
        pop_xuhao();
        acCarDengluJianceYpe.setText(xuhaoListjiance_type.get(1));
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        OkGo.getInstance().cancelTag(this);
        instances = null;
    }

    @OnClick({R.id.ac_car_denglu_waijianchedao, R.id.ac_car_denglu_jiance_ype,
            R.id.ac_car_denglu_cancle, R.id.ac_car_denglu_denglu})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ac_car_denglu_waijianchedao:
                //线号
                pop_xuhao.showAsDropDown(acCarDengluWaijianchedao);
                listview_xuhao.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> arg0, View arg1,
                                            int position, long arg3) {
                        acCarDengluWaijianchedao.setText(xuhaoList.get(position));
                        Line = xuhaoList.get(position);
                        pop_xuhao.dismiss();
                    }
                });
                break;
            case R.id.ac_car_denglu_jiance_ype:
                //检测类型
                pop_xuhaojiance_type.showAsDropDown(acCarDengluJianceYpe);
                listview_xuhaojiance_type.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> arg0, View arg1,
                                            int position, long arg3) {
                        acCarDengluJianceYpe.setText(xuhaoListjiance_type.get(position));
                        index = position;
                        pop_xuhaojiance_type.dismiss();
                    }
                });
                break;
            case R.id.ac_car_denglu_cancle:
                //返回
                finish();
                break;
            case R.id.ac_car_denglu_denglu:
                //登陆
                break;
        }
    }

    //popuwindow
    private View popu_xuhao_view;
    private LinearLayout parent22;
    private PopupWindow pop_xuhao = null;
    private ListView listview_xuhao;
    private MyProvincesListAdapter2 myProAdapter;
    private List<String> xuhaoList = new ArrayList<String>();

    private void pop_xuhao() {
        for (int i = 0; i < Constants.WAIJIAN_CHEDAO_CHEJIAN_XIANHAO.length; i++) {
            xuhaoList.add(i, Constants.WAIJIAN_CHEDAO_CHEJIAN_XIANHAO[i]);
        }
        pop_xuhao = new PopupWindow(this);
        popu_xuhao_view = getLayoutInflater().inflate(R.layout.item_setting_province_letter,
                null);
        pop_xuhao.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
        pop_xuhao.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
        pop_xuhao.setBackgroundDrawable(new BitmapDrawable());
        pop_xuhao.setFocusable(true);
        pop_xuhao.setOutsideTouchable(true);
        pop_xuhao.setContentView(popu_xuhao_view);
        parent22 = (LinearLayout) popu_xuhao_view.findViewById(R.id.setting_provinces_parent);
        listview_xuhao = (ListView) popu_xuhao_view.findViewById(R.id.setting_provinces_listview2);
        myProAdapter = new MyProvincesListAdapter2(this, xuhaoList);
        listview_xuhao.setAdapter(myProAdapter);
        parent22.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                pop_xuhao.dismiss();
            }
        });
    }


    //popuwindow
    private View popu_xuhao_viewjiance_type;
    private LinearLayout parent22jiance_type;
    private PopupWindow pop_xuhaojiance_type = null;
    private ListView listview_xuhaojiance_type;
    private MyProvincesListAdapter2 myProAdapterjiance_type;
    private List<String> xuhaoListjiance_type = new ArrayList<String>();

    private void pop_jiance_type() {
        for (int i = 0; i < Constants.JIANCE_TYPE_LISTS.length; i++) {
            xuhaoListjiance_type.add(i, Constants.JIANCE_TYPE_LISTS[i][0]);
        }
        pop_xuhaojiance_type = new PopupWindow(this);
        popu_xuhao_viewjiance_type = getLayoutInflater().inflate(R.layout.item_setting_province_letter,
                null);
        pop_xuhaojiance_type.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
        pop_xuhaojiance_type.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
        pop_xuhaojiance_type.setBackgroundDrawable(new BitmapDrawable());
        pop_xuhaojiance_type.setFocusable(true);
        pop_xuhaojiance_type.setOutsideTouchable(true);
        pop_xuhaojiance_type.setContentView(popu_xuhao_viewjiance_type);
        parent22jiance_type = (LinearLayout) popu_xuhao_viewjiance_type.findViewById(R.id.setting_provinces_parent);
        listview_xuhaojiance_type = (ListView) popu_xuhao_viewjiance_type.findViewById(R.id.setting_provinces_listview2);
        myProAdapterjiance_type = new MyProvincesListAdapter2(this, xuhaoListjiance_type);
        listview_xuhaojiance_type.setAdapter(myProAdapterjiance_type);
        parent22jiance_type.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                pop_xuhaojiance_type.dismiss();
            }
        });
    }
}
